<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    var tool = {
        sayHi:function(){
            console.log('hi');
        },
        walk:function() {
            console.log('散步');
        },
        eat:function(){
            console.log('吃猪蹄');
        }
    }
    //1.构造函数
    function Person () {
        this.sayHi = tool.sayHi;
        this.walk = tool.walk;
        this.eat = tool.eat;
    }

    //1
    var p1 = new Person();
    p1.sayHi();
    p1.walk();

     var p2 = new Person();
     p2.sayHi();
     p2.walk()

    //验证p1.sayHi == sayHi
     console.log(p1.sayHi== p2.sayHi);//
     
     //验证 p1 执行的 walk 方法 与 p2执行的 walk 方法是同一个吗?
     console.log(p1.walk ==p2.walk);

     //原型 可以解决 一个构造函数 创建 多个对象 引用多个相同函数的 问题
     
    </script>
</body>
</html>